package org.example.adminbackend.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.adminbackend.client.FileUploadServiceClient;
import org.example.adminbackend.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传代理控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/files")
public class FileUploadController {

    @Autowired
    private FileUploadServiceClient fileUploadServiceClient;

    /**
     * 上传文件代理接口
     */
    @PostMapping("/upload")
    public Result<String> uploadFile(@RequestParam("file") MultipartFile file) {
        try {
            log.info("代理文件上传请求: {}", file.getOriginalFilename());
            return fileUploadServiceClient.uploadFile(file);
        } catch (Exception e) {
            log.error("文件上传代理失败", e);
            return Result.error("文件上传失败: " + e.getMessage());
        }
    }
}